package org.example.admin.controller;

import java.util.List;

import org.example.admin.bo.UserBO;
import org.example.admin.dto.UserDto;
import org.example.admin.vo.UserVo;
import org.example.core.utils.PageUtils;
import org.example.core.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.example.admin.entity.UserEntity;
import org.example.admin.service.UserService;



/**
 * @author 小杰_cc
 * @version 1.0
 */
@RestController
@RequestMapping("/sys/backend/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R<?> list(UserDto userDto){
        PageUtils pageUtils = userService.list(userDto);
        return R.ok(pageUtils);
    }


    /**
     * 信息
     */
    @GetMapping("/{id}/detail")
    public R<?> detail(@PathVariable("id") Long id){
        UserVo user = userService.detail(id);
        return R.ok(user);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R<?> save(@RequestBody UserBO user){
        userService.save(user);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R<?> update(@RequestBody UserBO user){
        userService.update(user);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R<?> delete(@RequestBody List<Long> ids){
        return userService.delete(ids);
    }

}
